<?php
namespace app\admin\controller;

use app\common\controller\AdminBaseController;
use app\common\enum\IsDelete;
use app\common\ext\IDb;
use app\common\ext\IRequest;
use think\Db;

class AgentAdminTotal extends AdminBaseController{
    /**
     * @功能：根据用户统计收藏
     * @开发者：wdd
     * @return string
     */
    public function user_favorite_total(){
        //接收参数
        $user_id = IRequest::get("user_id");
        $nick = IRequest::get("nick");
        $phone = IRequest::get("phone");

        $agent_admin_favorite_where['ag.is_delete'] = IsDelete::No;
        if (!empty($user_id)) $agent_admin_favorite_where['us.user_id'] = $user_id;
        if (!empty($nick)) $agent_admin_favorite_where['us.nick'] = array("like","%{$nick}%");
        if (!empty($phone)) $agent_admin_favorite_where['us.phone'] = $phone;
        //取得数据
        $agent_admin_favorite_list = IDb::getInstance("agent_admin_favorite as ag")
            ->setDbFiled("ag.user_id,us.nick,us.phone,us.real,count(*) as favorite_num")
            ->setDbJoin('user as us','us.user_id=ag.user_id')
            ->setDbWhere($agent_admin_favorite_where)
            ->setDbGroup("ag.user_id")
            ->setDbOrder("favorite_num desc,ag.user_id")
            ->pag();
        if ($agent_admin_favorite_list === false){
            error('获取用户统计收藏失败');
        }

        //页面赋值
        $this->assign("user_id",$user_id);
        $this->assign("nick",$nick);
        $this->assign("phone",$phone);
        $this->assign("agent_admin_favorite_list",$agent_admin_favorite_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：信用卡收藏记录
     * @开发者：cxl
     * @return string
     */
    public function user_favorite_list(){
        //接收参数
        $user_id = IRequest::get("user_id",IRequest::NOT_EMPTY,"用户编号不能为空！");

        //取得数据
        $agent_admin_favorite_where['is_delete'] = IsDelete::No;
        $agent_admin_favorite_where['user_id'] = $user_id;
        $agent_admin_favorite_list = IDb::getInstance("agent_admin_favorite")
            ->setDbWhere($agent_admin_favorite_where)
            ->setDbOrder("agent_admin_favorite_id")
            ->pag();
        if ($agent_admin_favorite_list === false){
            error('获取收藏记录失败');
        }

        //设置layout
        $this->layout("layout_empty");

        //页面赋值
        $this->assign("user_id",$user_id);
        $this->assign("agent_admin_favorite_list",$agent_admin_favorite_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：根据信用卡统计收藏
     * @开发者：wdd
     * @return string
     */
    public function agent_admin_favorite_total(){
        //接收参数
        $agent_admin_id = IRequest::get("agent_admin_id");
        $nick = IRequest::get("nick");
        $real = IRequest::get("real");
        $phone = IRequest::get("phone");

        //判断是否为用户搜索
        $agent_admin_favorite_where['ag.is_delete'] = IsDelete::No;
        if ($agent_admin_id) $agent_admin_favorite_where['ag.agent_admin_id'] = $agent_admin_id;
        if ($nick) $agent_admin_favorite_where['aa.nick'] = array("like","%{$nick}%");
        if ($real) $agent_admin_favorite_where['aa.real'] = array("like","%{$real}%");
        if ($phone) $agent_admin_favorite_where['aa.phone'] = array("like","%{$phone}%");

        //取得数据
        $agent_admin_favorite_list = IDb::getInstance("agent_admin_favorite as ag")
            ->setDbFiled("ag.agent_admin_id,aa.nick,aa.real,aa.phone,count(*) as favorite_num")
            ->setDbJoin('agent_admin as aa','aa.agent_admin_id=ag.agent_admin_id')
            ->setDbWhere($agent_admin_favorite_where)
            ->setDbGroup("ag.agent_admin_id")
            ->setDbOrder("favorite_num desc,ag.agent_admin_id")
            ->pag();
        if ($agent_admin_favorite_list === false){
            error('获取信用卡统计收藏失败');
        }

        //页面赋值
        $this->assign("agent_admin_id",$agent_admin_id);
        $this->assign("nick",$nick);
        $this->assign("real",$real);
        $this->assign("phone",$phone);
        $this->assign("agent_admin_favorite_list",$agent_admin_favorite_list);

        //渲染模板输出
        return view();
    }

    /**
     * @功能：根据信用卡收藏记录
     * @开发者：wdd
     * @return string
     */
    public function agent_admin_favorite_list(){
        //接收参数
        $agent_admin_id = IRequest::get("agent_admin_id",IRequest::NOT_EMPTY,"用户编号不能为空！");

        //取得数据
        $agent_admin_favorite_where['is_delete'] = IsDelete::No;
        $agent_admin_favorite_where['agent_admin_id'] = $agent_admin_id;
        $agent_admin_favorite_list = IDb::getInstance("agent_admin_favorite")
            ->setDbWhere($agent_admin_favorite_where)
            ->setDbOrder("agent_admin_favorite_id")
            ->pag();
        if ($agent_admin_favorite_list === false){
            error('获取信用卡收藏记录失败');
        }

        //设置layout
        $this->layout("layout_empty");

        //页面赋值
        $this->assign("agent_admin_favorite_list",$agent_admin_favorite_list);

        //渲染模板输出
        return view();
    }
}